<template>
	<view class="my-points">
		<view class="top">
			<view class="box">
				<view class="flex-between" style="margin-bottom: 20rpx;">
					<view>您当前有</view>
					<view @click="exchange_record" class="flex-align">去兑换<u-icon name="arrow-right" color="#fff"></u-icon>
					</view>
				</view>
				<view class="flex-between">
					<view class="bold" style="font-size: 44rpx;">{{jifen}}积分</view>
					<view class="flex-align">
						<u-icon name="question-circle-fill" color="#fff" size="40rpx"></u-icon>积分说明
					</view>
				</view>
			</view>

			<u-text text="兑换明细" color="#323232" bold></u-text>
		</view>

		<u-cell-group>
			<u-cell v-for="item in list" :key="item.id">
				<view slot="title">
					<!-- <view class="name bold">{{ item.name }}</view> -->
					<!-- <view class="name bold">积分签到</view> -->
					<view class="name " v-if="item.op == 0">{{item.simple_type}}</view>
					<view class="name " v-if="item.op == 1">{{item.simple_type}}</view>
					<view class="rest">余额:{{ item.else_points }}积分</view>
				</view>
				<view slot="value" class="text-right">
					<view class="increate bold" v-if="item.op == 0"><text v-if="item.is_valid == 0">已过期</text> +{{ item.points }}积分</view>
					<!-- op 0   + -->
					<!-- op 1   - -->
					<view class="decreate bold" v-if="item.op == 1">-{{ item.points }}积分</view>
					<view class="date">{{ item.create_at }}</view>
				</view>
			</u-cell>
		</u-cell-group>
	</view>
</template>

<script>
	const index = require('@/api/personal/index.js')
	export default {
		data() {
			return {
				list: [],
				jifen: ''
			}
		},
		onLoad(options) {
			let that = this
			that.getPointsRecord()
			that.getPoints()
		},
		methods: {
			async getPoints() {
				uni.showLoading({
					title: "加载中...",
					mask: true,
				});
				let params = {
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
					open_id: uni.getStorageSync('openid'),
				};
				let res = await index.getPoints(params);
				if (res.code === 1) {
					this.jifen = res.data.result

					this.$nextTick(() => {
						uni.hideLoading();
					});
				}
			},
			// 积分记录
			async getPointsRecord() {
				uni.showLoading({
					title: "加载中...",
					mask: true,
				});
				let params = {
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
					open_id: uni.getStorageSync('openid'),
				};
				let res = await index.getPointsRecord(params);
				if (res.code === 1) {
					this.list = res.data.result
					this.$nextTick(() => {
						uni.hideLoading();
					});
				}
			},
			exchange_record(){
				uni.navigateTo({
					url:'../../page_points/page_points/points_mall'
				})
			}


		}
	}
</script>

<style lang="scss" scoped>
	.my-points {
		.top {
			background-color: #f3f3f3;
			padding: 30rpx;

			.box {
				color: #fff;
				padding: 40rpx 30rpx;
				background: linear-gradient(0deg, #528EFF, #2F75FA);
				border-radius: 20rpx;
				margin-bottom: 20rpx;
			}
		}

		/deep/.u-cell-group {
			.name {
				color: #333;
				font-size: 24rpx;
				font-weight: 600;
				// 
				
			}

			.increate {
				color: #ff4000;
				font-size: 24rpx;
			}

			.decreate {
				color: #19b408;
				font-size: 24rpx;
			}

			.rest,
			.date {
				margin-top: 14rpx;
				font-size: 22rpx;
				color: #333;
			}
		}
	}
</style>
